﻿namespace Exporter
{
    using System.Collections.Generic;
    using System.Threading;
    using Exporters;
    using Exporters.Implementations;
    using MoviesDataBase;

    /// <summary>
    /// The movies exporter.
    /// </summary>
    public static class Exporter
    {
        /// <summary>
        /// Exports the specified filename.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <param name="movies">The movies.</param>
        /// <param name="format">The format.</param>
        public static void Export(string filename, IEnumerable<Movie> movies, Format format)
        {
            ThreadStart ts = new ThreadStart(() =>
            {
                IFileExporter exporter = null;

                switch (format)
                {
                    case Format.PDF:
                        exporter = new PdfExporter();
                        break;

                    case Format.Doc:
                        exporter = new WordExport();
                        break;

                    case Format.XML:
                        exporter = new XmlExporter();
                        break;

                    case Format.TXT:
                        exporter = new TextExporter();
                        break;
                }

                if (exporter != null)
                {
                    exporter.Export(filename, movies);
                }
            });

            Thread thread = new Thread(ts);
            thread.Start();
        }
    }
}
